package com.java.controller;

import com.java.model.MediaAccount;
import com.java.model.Result;
import com.java.service.MediaAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/mediaAccount")
public class MediaAccountController {

    @Autowired
    private MediaAccountService mediaAccountService;

    /**
     * 短信验证
     * @param phoneNum
     * @return
     * @throws Exception
     */
    @PostMapping("/message")
    @ResponseBody
    public Result message(String phoneNum) throws Exception {
        return mediaAccountService.message(phoneNum);
    }

    /**
     * 跳转到资源管理的微信
     * @return
     */
    @GetMapping("/weChat")
    public String weChat(Model model){
        List<MediaAccount> mediaAccount1 = mediaAccountService.saveList();
        model.addAttribute("mediaAccount", mediaAccount1);
        return "/MediaAccount/weChat";
    }

    /**
     * 同意自媒体入驻
     * @param mediaAccount
     * @return
     */
    @PostMapping("/agree")
    @ResponseBody
    public Result agree(MediaAccount mediaAccount) {
        return mediaAccountService.agree(mediaAccount);
    }
    /**
     * 拒绝自媒体入驻
     * @param mediaAccount
     * @return
     */
    @PostMapping("/refused")
    @ResponseBody
    public Result refused(MediaAccount mediaAccount) {
        return mediaAccountService.refused(mediaAccount);
    }

    /**
     * 查询微信列表
     * @param mediaAccount
     * @return
     */
    @PostMapping("/weChatList")
    @ResponseBody
    public Result weChatList(MediaAccount mediaAccount){ // id 没能传过去
        return mediaAccountService.list(mediaAccount);
    }

    /**
     * 跳转查看账号详情
     * @return
     */
    @GetMapping("/view")
    public String view(int id, Model model) {
        Result result = mediaAccountService.get(id);
        if (result.getCode().equals("0")) {
            model.addAttribute("result", result.getData());
        }
        return "/MediaAccount/view";
    }

    /**
     * 跳转到资源管理的微博
     * @return
     */
    @GetMapping("/microblog")
    public String microblog(){
        return "/MediaAccount/microblog";
    }

    /**
     * 查询微博列表
     * @param mediaAccount
     * @return
     */
    @PostMapping("/microblogList")
    @ResponseBody
    public Result microblogList(MediaAccount mediaAccount){
        return mediaAccountService.list(mediaAccount);
    }

    /**
     * 跳转到资源管理的抖音
     * @return
     */
    @GetMapping("/trill")
    public String trill(){
        return "/MediaAccount/trill";
    }

    /**
     * 查询抖音列表
     * @param mediaAccount
     * @return
     */
    @PostMapping("/trillList")
    @ResponseBody
    public Result trillList(MediaAccount mediaAccount){
        return mediaAccountService.list(mediaAccount);
    }

    /**
     * 跳转到资源管理的快手
     * @return
     */
    @GetMapping("/quickly")
    public String quickly(){
        return "/MediaAccount/quickly";
    }

    /**
     * 查询快手列表
     * @param mediaAccount
     * @return
     */
    @PostMapping("/quicklyList")
    @ResponseBody
    public Result quicklyList(MediaAccount mediaAccount){
        return mediaAccountService.list(mediaAccount);
    }

}
